/*/

	Written By:					Leong C. W., Johnathon

	Written Date:				17 / July / 2008
	
	Email:						johnathon dot leong at gmail dot com
	
	Operating System Used:		Ubuntu 8.04
	
	IDE:						"gedit" from Ubuntu 8.04 is used
	
	Programming Language:		C++
	
	Compiler:					g++
	
	Disclaimer:					Copyright (c) 2008	Leong C. W., Johnathon
								
								Permission is hereby granted, free of charge, to any person obtaining a copy
								of this software and associated documentation files (the "Software"), to
								deal in the Software without restriction, including without limitation the
								rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
								sell copies of the Software, and to permit persons to whom the Software is
								furnished to do so, subject to the following conditions:

								The above copyright notice and this permission notice shall be included in
								all copies or substantial portions of the Software.

								THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
								IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
								FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
								AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
								LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
								FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
								IN THE SOFTWARE.


------------------------------------------------------------------------------------------------------------

	Function Name:				int main(void);
	
	Function Purpose:			This function is to test the functionality of "linux_kbhit.h".

	Number of Input Argument:	N/A
	
	Input Argument type:		N/A
	
	Purpose of Input Argument:	N/A
		
	Return Value type:			int
	
	Purpose of Return Value:	To indicate main function has exited properly.

	Known Issues:				Please refer to "linux_kbhit.h" for known issues.

/*/

#include <stdio.h>
#include <iostream>
#include "linux_kbhit.h"

int main(void)
{
	int previous_keystroke = 0;
	
	printf("\n");
	printf("Type any key to see the return ASCII int of the key pressed.\n");
	printf("The program will start in 1sec. Press <Esc> to quit...\n\n");
	sleep(1);
	
	while(1)
	{
		int value = linux_kbhit();
		
		// key stroke detected
		if (value != -1)
		{
			// printing of key integer value
			printf("%d\n", value);
		}

		// detection of <Esc> key.	# of integer value set:	1
		//							integer value:			27
		if ((previous_keystroke == 27) && (value == -1))
			break;
		previous_keystroke = value;
		
		// printing of '.'s to prove non-blocking of kbhit()
		printf(".");
	}
	
	printf("\n");
	printf("<Esc> key pressed. Bye bye\n\n");
	
	return 0;
}

